﻿using DevExpress.XtraReports.UI;
using DevTeam;
using System;
using System.Drawing;

namespace ConfExpert.Forms.Rapor
{
    public partial class AksesuarIrsaliye : DevExpress.XtraReports.UI.XtraReport
    {
        int IrsaliyeNo;
        DateTime SevkTarihi;
        string PartiId, Details;
        public AksesuarIrsaliye()
        {
            InitializeComponent();
        }
        public AksesuarIrsaliye(string partiId, string _irsaliyeNo, DateTime sevkTarihi, string details, string _teslimEden, string teslimAlan)
            : this()
        {
            PartiId = partiId;
            IrsaliyeNo = Convert.ToInt32(_irsaliyeNo);
            SevkTarihi = sevkTarihi;
            Details = details;
            tcSevkiyatci.Text = _teslimEden;
            tcTeslimAlan.Text = teslimAlan;
            myData1.Merge(Session.DataManager.ExecuteDataSet("GetAksesuarIrsaliye", partiId, _irsaliyeNo, sevkTarihi, details));
            myData1.AksesuarIrsaliye.Merge(myData1.Tables["Table"]);
            myData1.AksesuarIrsaliyeLines.Merge(myData1.Tables["Table1"]);

            AksesuarIrsaliyeLines aksesuarIrsaliyeLines1 = (AksesuarIrsaliyeLines)xrSubreport1.ReportSource;
            aksesuarIrsaliyeLines1.fillTables(partiId, _irsaliyeNo, sevkTarihi, details);

            xrTableCell32.BeforePrint += new System.Drawing.Printing.PrintEventHandler(xrTableCell32_BeforePrint);
            xrTableCell12.BeforePrint += new System.Drawing.Printing.PrintEventHandler(xrTableCell12_BeforePrint);
            xrTableCell15.BeforePrint += new System.Drawing.Printing.PrintEventHandler(xrTableCell12_BeforePrint);
            //xrTableCell16.BeforePrint += new System.Drawing.Printing.PrintEventHandler(xrTableCell32_BeforePrint);
            xrTableCell24.BeforePrint += new System.Drawing.Printing.PrintEventHandler(xrTableCell12_BeforePrint);

        }

        void xrTableCell12_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
            gr.PageUnit = GraphicsUnit.Millimeter;
            int factor = 10;

            XRLabel label = (XRLabel)sender;

            float newSize = 9.75f;
            Font defaultFont = new System.Drawing.Font("Times New Roman", newSize);

            float stringWidth = gr.MeasureString(label.Text, defaultFont).Width;
            float labelWidth = label.WidthF;


            if (labelWidth < stringWidth * factor)
                newSize = defaultFont.Size * label.Width / stringWidth / factor;


            label.Font = new Font(defaultFont.FontFamily, newSize);
            gr.Dispose();
        }

        void xrTableCell32_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
            gr.PageUnit = GraphicsUnit.Millimeter;
            int factor = 10;

            XRLabel label = (XRLabel)sender;

            float newSize = 8f;
            Font defaultFont = new System.Drawing.Font("Times New Roman", newSize);

            float stringWidth = gr.MeasureString(label.Text, defaultFont).Width;
            float labelWidth = label.WidthF;


            if (labelWidth < stringWidth * factor)
                newSize = defaultFont.Size * label.Width / stringWidth / factor;


            label.Font = new Font(defaultFont.FontFamily, newSize);
            gr.Dispose();
        }

        private void xrSubreport1_BeforePrint_1(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            ((AksesuarIrsaliyeLines)((XRSubreport)sender).ReportSource).TalepID.Value =
       Convert.ToInt32(GetCurrentColumnValue("AksesuarCikisTalebiId"));
        }

    }
}
